from mainfunc.baseapi import BaseApi
from config.fileName import title_dic_zj


class HandleFilezj(BaseApi):
    def __init__(self):
        self.url = "http://www.csf.com.cn/publish/main/1046/1060/index.html"
        self.req = BaseApi.getSource(self.url)

    def downF(self):
        for file_name in list(title_dic_zj.keys()):
            partten = f'''<div class="list_content_container"><a href="/publish/main/1046/1060/(\S*?)" target="\d+">{file_name}'''
            try:
                self.download_name = BaseApi.searchName(partten, self.req)
                self.download_url = BaseApi.combineUrl('http://www.csf.com.cn/publish/main/1046/1060/', self.download_name)
                fileTpye = self.download_name.split('.')[-1]
                BaseApi.cleanFile(title_dic_zj[file_name])
                BaseApi.downFile(fileTpye, file_name, self.download_url)
                print(f'文件:{file_name}处理成功')
            except Exception as e:
                print(f'文件:{file_name}处理失败,错误信息：{e}')
